<?php
    include "db.func.php";

    function writtenMangaInDb( $data )
    {
        $query = 'SELECT LAST_INSERT_ID() FROM manga';
        $id    = getQueryResults( $query );
        $id    = count( $id ) + 1;

        $query = sprintf(
        'INSERT INTO manga VALUES ( %d, \'%s\', \'%s\', \'%s\', \'%i\', \'%s\', \'%s\', \'%s\', \'%s\', \'%i\' );',
        $id, $data['nameRu'], $data['nameEn'], $data['nameRo'], $data['volumeCount'], $data['author'],
        $data['translator'],  $data['description'], $data['description'], $data['archive'], 
        $data['finished'] );

        if ( executeQuery( $query ) )
        {
            printResultForAdmin( 'Аниме записано' );
        }
        else
        {
            printResultForAdmin( 'Ошибка в записи аниме' );
        }
    }
    
    function getManga()
    {
        
    }
    
    function getTag()
    {
        $query = "";
        return getQueryResults( $query );
    }
    /*
    function getMangaCountInTag()
    {
        $qGetCloud = "SELECT tags.tag, COUNT(posts_tags.tagid) AS posts_count" .
                    " FROM posts_tags LEFT JOIN tags ON posts_tags.tagid=tags.id" .
                    " GROUP BY tags.id";
        $res = $this->db->query($qGetCloud);
        if ( $res->num_rows() == 0 )
        {
            return false;
        }
        else
        {
            return $res->result_array();
        }
    }
    
    
    if ($tagcloud === FALSE) {
        echo "Данные не найдены";
    }
    else {
        $min = $tagcloud[0]['posts_count'];
        $max = $tagcloud[0]['posts_count'];
        for ($i = 1; $i < count($tagcloud); $i++)
        {
            if ($tagcloud[$i]['posts_count'] > $max)
            {
                $max = $tagcloud[$i]['posts_count'];
            }
            if ($tagcloud[$i]['posts_count'] < $min)
            {
                $min = $tagcloud[$i]['posts_count'];
            }
        }
        $minSize = 70;
        $maxSize = 150;
        foreach ($tagcloud as $item)
        {
            if ($min == $max)
            {
                $fontSize = round(($maxSize - $minSize) / 2 + $minSize);
            }
            else
            {
                $fontSize = round((($item['posts_count'] - $min)/($max - $min)) * ($maxSize - $minSize) + $minSize);
            }
            echo "<span style=\"font-size:".$fontSize."%\">".$item['tag']." (".$item['posts_count'].") </span>";
        }
    }*/
?>